from flask import Response
from .NetworkModel_pb2 import PBResponse


def success_response(pb_model):
    resp = PBResponse()
    resp.result = True
    resp.data = pb_model.SerializeToString()
    resp = resp.SerializeToString()
    return Response(resp)


def failure_response(errorMsg):
    resp = PBResponse()
    resp.result = False
    resp.errorMsg = errorMsg
    resp = resp.SerializeToString()
    return Response(resp)


def req_data_error_response():
    resp = PBResponse()
    resp.result = False
    resp.errorMsg = '请求数据不正确'
    resp = resp.SerializeToString()
    return Response(resp, status=400)


def req_data_miss_parameter(errorMsg):
    resp = PBResponse()
    resp.result = False
    resp.errorMsg = errorMsg
    resp = resp.SerializeToString()
    return Response(resp, status=406)
